<template>
  <view class="carbox" v-if="totail !=0">
    <!-- 收货地址 -->
    <view class="frist">
      <view class="xuanzequ" v-if="JSON.stringify(address1)=='{}'">
        <button type="primary" size="mini" @click="getaddress">选择收货地址</button>
      </view>
      <view class="addressinfo" @click="getaddress" v-else>
        <view class="one">
          <view class="one1">
            <view class="name">收货人：{{address1.userName}}</view>
            <view class="one11">
              <view class="ipone">电话：{{address1.telNumber}}</view>
              <uni-icons type="right" size="16"></uni-icons>
            </view>
          </view>
        </view>
        <view class="two">
          <view class="addree">收货地址:</view>
          <view class="addree1">{{dizhi}}</view>
        </view>
      </view>
      <view class="tupian">
        <view class="itemimg" v-for="(item,i) in yanse" :key="i" :style="{backgroundColor:i%2==0?yanse1[0]:yanse1[1]}"></view>
      </view>
    </view>
    <view class="car_title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text>购物车</text>
    </view>
    <view class="list">
      <uni-swipe-action>
        <view class="carlist" v-for="(item,i) in cart" :key="i">
          <uni-swipe-action-item :right-options="options"  @click="bindClick(item)" :disabled="!item.goods_state">
            <my-goods :goods="item" @radio-change="gaib" :kaiguan="true" @mun-change="a5"></my-goods>
          </uni-swipe-action-item>
        </view>
      </uni-swipe-action>
    </view>
    <my-settle></my-settle>
  </view>
  <view class="qingko" v-else>
    <image src="../../static/tabicon/kk.jpg"></image>
    <text>空空如也</text>
  </view>
</template>

<script>
  import {mapGetters,mapState,mapMutations} from "vuex"

  export default {
   
    computed:{
      ...mapState('m_cat',['cart']),
      ...mapGetters('m_cat',['totail']),
      ...mapState('m_addrees',['address1']),
      ...mapGetters('m_addrees',['dizhi'])
      
    },
    onShow() {
      this.sethuibiao()
      
    },
    data(){
      return{
        options:[
          {
             text: '删除',
            style: {
                backgroundColor: '#c00000'
            }
          }
        ],
        yanse: [...new Array(20).keys()],
        yanse1:['red','blue'],
        
        
      }
    },
 
    methods: {
      sethuibiao(){
        if(this.totail==0) return uni.removeTabBarBadge({
          index:2
        })
        uni.setTabBarBadge({
          index:2,
          text:this.totail+'' //必须是字符串
        })
      },
      
      ...mapMutations('m_cat',['gaibianstate','updatemun','deleteitem']),
      ...mapMutations('m_addrees',['addd']),
      //增加cart
      gaib(e){
        this.gaibianstate(e)
        this.sethuibiao()
      },
      //更新count
      a5(e){
        this.updatemun(e)
        this.sethuibiao()
       
      },
      //删除商品
      bindClick(item){
        this.deleteitem(item)
        this.sethuibiao()
        
        
      },
      //请求收获地址的
      async getaddress(){
        const a=await uni.chooseAddress().catch(res=>res) //catch 不管是失败还是成功都能执行
        if(!a.cityName) return
        this.addd(a)
      }
      
    }
  }
</script>

<style lang="scss">
  .car_title{
    display:flex;
    height: 40px;
    align-items: center;
    border-bottom: 1px solid #efefef;
    text{
      margin-left: 5px;
      font-size: 14px;
    }
  }
  .carbox{
    width: 750rpx;
    box-sizing: border-box;
  }
  .tupian{
    display: flex;
    justify-content: space-around;
    .itemimg{
      height: 5px;
      width: 12px;
    }
    
  }
  .xuanzequ{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 90px;
  }
  .addressinfo{
    font-size: 14px;
    padding: 0 10px;
    margin: 10px 0;
    .one{
      .one1{
        display: flex;
        justify-content: space-between;
        .name{}
        .one11{
          display: flex;
        }
        .ipone{}
      }
    }
    .two{
      display: flex;
      margin: 10px 0;
      .addree{
        white-space: nowrap;
      }
    }
    
  }
  .list{
    padding-bottom: 50px;
  }
  .qingko{
    height: 750rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #fafafa;
    image{
      width: 100px;
      height: 100px;
    }
    text{
      margin-top:10px ;
      font-size: 12px;
      color:gray;
    }
  }

</style>
